﻿using HirelReg;
using Microsoft.Win32;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HirelSeriesH
{
    public partial class RegForm : UIForm
    {
        public RegForm()
        {
            InitializeComponent();
        }

        private void RegForm_Load(object sender, EventArgs e)
        {
            TbSysCode.Text = RegCode.GetMachineCodeF();
        }

        private void btnCopyCode_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(RegCode.GetMachineCodeF());
            UIMessageDialog.ShowMessageDialog("复制成功", UILocalize.InfoTitle, false, UIStyle.Colorful);
        }

        private void BtnReg_Click(object sender, EventArgs e)
        {
            string regCode = TbRegCode.Text;
            if ((regCode == null) || (regCode.Trim() == ""))
            {
                UIMessageDialog.ShowMessageDialog("请输入注册码", UILocalize.InfoTitle, false, UIStyle.Colorful);
                return;
            }
            //写注册表
            RegistryKey regWrite;
            //往HKEY_CURRENT_USER主键里的Software子键下写一个名为“Hirel”的子键
            //如果Hirel子键已经存在系统会自动覆盖它
            regWrite = Registry.CurrentUser.CreateSubKey(@"Software\Hirel");
            //往Hirel子键里添RegCode
            regWrite.SetValue("RegCode", regCode);
            //关闭该对象
            regWrite.Close();
            UIMessageDialog.ShowMessageDialog("写入注册码成功", UILocalize.InfoTitle, false, UIStyle.Colorful);
            Close();
        }

    }
}
